package com.recharge.controller;


import java.math.BigDecimal;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.recharge.base.ResponseInfo;
import com.recharge.base.ResponseInfoEnum;
import com.recharge.wk.domain.TradeMerbalanceFlow;
import com.recharge.wk.domain.TradeMerchant;
import com.recharge.wk.domain.TradeSaleprice;
import com.recharge.wk.mapper.ITradeMerbalanceFlowMapper;
import com.recharge.wk.mapper.ITradeMerchantMapper;

@Controller
@RequestMapping("/tradeMerchant")
public class TradeMerchantController {
	

    @Autowired
    private ITradeMerchantMapper iTradeMerchantMapper;
    
    @Autowired
    private ITradeMerbalanceFlowMapper iTradeMerbalanceFlowMapper;


    private Logger logger = LoggerFactory.getLogger(getClass());
	
	
   /**
     * 商户余额的查询controller
     * @return
     */
    @RequestMapping("/queryMerList")
    @ResponseBody
    public ResponseInfo queryMeriList(
    		@RequestParam("merId")String merId,
            @RequestParam("merName") String merName,
            @RequestParam("curr") Integer curr,
            @RequestParam("pageSize") Integer pageSize){
        ResponseInfo responseInfo = new ResponseInfo();
        
//        TradeMerchant tradeMerchant = new TradeMerchant();
//        tradeMerchant.setMerId(merId);
//        tradeMerchant.setMerName(merName);
        List<TradeMerchant> tradeMerchants = iTradeMerchantMapper.selectMerList(merId,merName, curr, pageSize);
        
        
        responseInfo.setInfoEnum(ResponseInfoEnum.SUCCESS);
        responseInfo.setData(tradeMerchants);
        responseInfo.setCount(iTradeMerchantMapper.countMer(merId,merName));
        return responseInfo;
    }
    
    @RequestMapping("/updateBalance")
    @ResponseBody
    public ResponseInfo updateBalance(
    		@RequestParam("merId") String merId,
    		@RequestParam("merName") String merName,
            @RequestParam("balanceAdd") BigDecimal balanceAdd,
            @RequestParam("remark") String remark) {
        ResponseInfo responseInfo = new ResponseInfo();

        int insertflow = iTradeMerbalanceFlowMapper.insertFlow(merId,merName,balanceAdd,remark);
        int add = iTradeMerchantMapper.updateAddBalance(merId,merName ,balanceAdd);
        logger.info("insertflow:{}, add:{}",insertflow,add);
        responseInfo.setInfoEnum(ResponseInfoEnum.SUCCESS);
        return responseInfo;
    }
}
